use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .create_table(
                Table::create()
                    .table(CommitInfo::Table)
                    .if_not_exists()
                    .col(pk_auto(CommitInfo::Id))
                    .col(integer(CommitInfo::GitlabInfoId))
                    .col(big_integer(CommitInfo::ProjectId))
                    .col(string_null(CommitInfo::Branch))
                    .col(string_null(CommitInfo::CommitId))
                    .col(string_null(CommitInfo::Title))
                    .col(string_null(CommitInfo::AuthorName))
                    .col(string_null(CommitInfo::AuthorEmail))
                    .col(date_time_null(CommitInfo::CrateedAt))
                    .col(big_integer_null(CommitInfo::Additions))
                    .col(big_integer_null(CommitInfo::Deletions))
                    .col(big_integer_null(CommitInfo::Total))
                    .to_owned(),
            )
            .await
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .drop_table(Table::drop().table(CommitInfo::Table).to_owned())
            .await
    }
}

#[derive(DeriveIden)]
enum CommitInfo {
    Table,
    Id,
    GitlabInfoId,
    ProjectId,
    Branch,
    CommitId,
    Title,
    AuthorName,
    AuthorEmail,
    CrateedAt,
    Additions,
    Deletions,
    Total,
}
